package com.jeesite.modules.billnopattern.web;

import java.util.List;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.billnopattern.entity.BillNoPattern;
import com.jeesite.modules.billnopattern.service.BillNoPatternService;

/**
 * 单据编码记录表Controller
 * @author 码脑洞
 * @version 2025-04-13
 */
@Controller
@RequestMapping(value = "${adminPath}/billnopattern/billNoPattern")
public class BillNoPatternController extends BaseController {

	@Autowired
	private BillNoPatternService billNoPatternService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public BillNoPattern get(Long autoId, boolean isNewRecord) {
		return billNoPatternService.get(autoId, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("billnopattern:billNoPattern:view")
	@RequestMapping(value = {"list", ""})
	public String list(BillNoPattern billNoPattern, Model model) {
		model.addAttribute("billNoPattern", billNoPattern);
		return "modules/billnopattern/billNoPatternList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("billnopattern:billNoPattern:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<BillNoPattern> listData(BillNoPattern billNoPattern, HttpServletRequest request, HttpServletResponse response) {
		billNoPattern.setPage(new Page<>(request, response));
		Page<BillNoPattern> page = billNoPatternService.findPage(billNoPattern);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("billnopattern:billNoPattern:view")
	@RequestMapping(value = "form")
	public String form(BillNoPattern billNoPattern, Model model) {
		model.addAttribute("billNoPattern", billNoPattern);
		return "modules/billnopattern/billNoPatternForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("billnopattern:billNoPattern:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated BillNoPattern billNoPattern) {
		billNoPatternService.save(billNoPattern);
		return renderResult(Global.TRUE, text("保存单据编码记录表成功！"));
	}
	
}